package com.example.formatter;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.http.ResponseEntity;
import org.springframework.http.MediaType;

@RestController
@RequestMapping("/api")
public class FormatController {

    @Autowired
    private FormatService formatService;

    @PostMapping(value = "/format", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<FormatResponse> formatCode(@RequestBody FormatRequest request) {
        String formatted = formatService.format(request.getLanguage(), request.getCode());
        return ResponseEntity.ok(new FormatResponse(formatted));
    }
}

class FormatRequest {
    private String language;
    private String code;

    public String getLanguage() { return language; }
    public void setLanguage(String language) { this.language = language; }
    public String getCode() { return code; }
    public void setCode(String code) { this.code = code; }
}

class FormatResponse {
    private String formattedCode;
    public FormatResponse(String formattedCode) { this.formattedCode = formattedCode; }
    public String getFormattedCode() { return formattedCode; }
    public void setFormattedCode(String formattedCode) { this.formattedCode = formattedCode; }
}
